package com.sgb.zhaocai.view.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import com.sgb.link.entity.PickInvitedApply;
import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PickInvitedApplyAdapter extends BaseRecycleAdapter<PickInvitedApply> {

    private TextView tvTimeTitle;
    private TextView tvTimeContext;
    private TextView tvTwoTitle;
    private TextView tvTwoContext;
    private TextView invitedState;
    private TextView tvState;
    private IChildClick iChildClick;
    private String fromWhere = "1";

    public PickInvitedApplyAdapter(Context context, List<PickInvitedApply> datas) {
        super(context, R.layout.item_pick_invited_apply, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final PickInvitedApply entity) {
        holder.setBinding(BR.viewModel, entity);

        tvState = holder.itemView.findViewById(R.id.tv_state);
        tvTimeTitle = holder.itemView.findViewById(R.id.tv_time_title);
        tvTimeContext = holder.itemView.findViewById(R.id.tv_time_context);
        tvTwoTitle = holder.itemView.findViewById(R.id.tv_two_title);
        tvTwoContext = holder.itemView.findViewById(R.id.tv_two_context);
        invitedState = holder.itemView.findViewById(R.id.invited_state);

        if ("1".equals(fromWhere)) {
            tvState.setText("招标报名");
            tvTimeTitle.setText("报名时间：");
            tvTimeContext.setText(entity.getApplyStartTime() + "-" + entity.getApplyEndTime());
            tvTwoTitle.setText("投标人限定：");
            tvTwoContext.setText(entity.getRule());
            invitedState.setText("邀请报名");
        } else if ("2".equals(fromWhere)) {
            tvState.setText("竞价中");
            tvTimeTitle.setText("发布时间：");
            tvTimeContext.setText(entity.getCreated());
            tvTwoTitle.setText("竞价家数：");
            tvTwoContext.setText(entity.getOfferNum());
            invitedState.setText("邀请竞价");
        }

        invitedState.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iChildClick.onClick(entity);
            }
        });
    }

    public interface IChildClick {
        void onClick(PickInvitedApply pickInvitedApply);
    }

    public void onIChildClick(IChildClick iChildClick) {
        this.iChildClick = iChildClick;
    }

    public void setFromWhere(String fromWhere) {
        this.fromWhere = fromWhere;
    }

}
